package com.tang.web;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Tang
 * @classname UserController
 * @description [  ]
 * @date 2021/5/3 10:24
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping("/index")
    public Map<String, Object> index() {
        Map<String, Object> map = new HashMap<>(16);
        map.put("username", "user");
        return map;
    }

    @PreAuthorize(value = "hasRole('USER')")
    @GetMapping("/userIndex")
    public Map<String, Object> userIndex() {
        Map<String, Object> map = new HashMap<>(16);
        map.put("username", "user");
        return map;
    }

    @GetMapping("/adminIndex")
    public Map<String, Object> adminIndex() {
        Map<String, Object> map = new HashMap<>(16);
        map.put("username", "admin");
        return map;
    }

    @PostMapping("/login")
    public Map<String, Object> login() {
        Map<String, Object> map = new HashMap<>(16);
        map.put("username", "admin");
        return map;
    }
}